package org.xin.framework.controller;

import cn.hutool.captcha.CaptchaUtil;
import cn.hutool.captcha.ShearCaptcha;
import cn.hutool.core.lang.Dict;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;
import org.xin.common.constant.Constants;
import org.xin.common.result.Result;
import org.xin.framework.component.CaptchaComponent;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * @author ：xin
 * @date ：Created in 2021/10/2
 * @desc <p>  </p>
 * @modified By：$
 * @version: $
 */
@Api(tags = "公共模块")
@CrossOrigin
@Controller
@RequestMapping("/common")
public class CommonController {
    @Autowired
    private CaptchaComponent captchaComponent;

    @Value("${server.servlet.context-path}")
    private String contextPath;

    //    @PreAuthorize("@ss.hasPermi('tool:swagger:view')")
    @ApiOperation("跳转至Swagger文档")
    @GetMapping("swagger")
    public void swagger(HttpServletResponse response) {
        try {
            response.sendRedirect(contextPath + "/doc.html#");
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

    @ApiOperation("获取验证码图片")
    @GetMapping("captchaImg")
    @ResponseBody
    public Result captcha() {
        return Result.success(captchaComponent.generateCaptcha());
    }
}
